home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / lh113src.zip / LZS.ASM < prev    next >
Assembly Source File  |  1989-05-14  |  24KB  |  1,165 lines

  1. page    66, 120                    ;
  2. ;$_init                        ;
  3. ;***********************************************;
  4. ;       LHarc version 1.13b (c) Yoshi 1988-89.    ;
  5. ;           LZSS module : 1989/ 5/14        ;
  6. ;                        ;
  7. ;       é▒é╠òöò¬é═üAë£æ║É░òFÄüé╠ékéyé`éqéhû@é╠    ;
  8. ;       ébâ\ü[âXé≡ÄQìlé╔ïLÅqé╡é╜üB        ;
  9. ;       é▄é╜üAìéæ¼ë╗é╠é╜é▀é╔ÄOû╪ÿaòFÄüé╠ LArc    ;
  10. ;       é╠â\ü[âXâèâXâgé≡ÄQìlé╔é│é╣é─Æ╕éóé╜üB    ;
  11. ;                        ;
  12. ; HTAB = 8                    ;
  13. ;***********************************************;
  14.                         ;
  15. extrn    __fgetc:near                ;
  16. extrn    __fputc:near                ;
  17.                         ;
  18. ;***************************************    ;
  19. ;    getc macro                ;
  20. ;        bx: address of FILE struc        ;
  21. ;        ax: input char (return)        ;
  22. ;***************************************    ;
  23. getc@    macro                    ;
  24.     local    getc1, getc2            ;
  25.     dec    word ptr [bx]            ;
  26.     jl    getc1                ;
  27.     inc    word ptr [bx+10]        ;
  28.     mov    bx, [bx+10]            ;
  29.     mov    al, [bx-1]            ;
  30.     xor    ah, ah                ;
  31.     jmp    getc2                ;
  32. getc1:                        ;
  33.     push    dx                ;
  34.     push    cx                ;
  35.     push    bx                ;
  36.     call    __fgetc                ;
  37.     pop    bx                ;
  38.     pop    cx                ;
  39.     pop    dx                ;
  40. getc2:                        ;
  41.     endm                    ;
  42.                         ;
  43. getc_crc@    macro                ;
  44.     local    getc1, getc2            ;
  45.     dec    word ptr [bx]            ;
  46.     jl    getc1                ;
  47.     inc    word ptr [bx+10]        ;
  48.     mov    bx, [bx+10]            ;
  49.     mov    al, [bx-1]            ;
  50.     xor    ah, ah                ;
  51.     jmp    getc2                ;
  52. getc1:                        ;
  53.     call    crcgetc                ;
  54. getc2:                        ;
  55.     endm                    ;
  56.                         ;
  57. ;***************************************    ;
  58. ;    putc macro                ;
  59. ;        ax: output char            ;
  60. ;        bx: address of FILE struc        ;
  61. ;***************************************    ;
  62. putc@    macro                    ;
  63.     local    putc1, putc2            ;
  64.     inc    word ptr [bx]            ;
  65.     jge    putc1                ;
  66.     inc    word ptr [bx+10]        ;
  67.     mov    bx, [bx+10]            ;
  68.     mov    [bx-1], al            ;
  69.     jmp    short putc2            ;
  70. putc1:                        ;
  71.     call    fputc                ;
  72. putc2:                        ;
  73.     endm                    ;
  74.                         ;
  75. putc_crc@    macro                ;
  76.     local    putc1, putc2            ;
  77.     inc    word ptr [bx]            ;
  78.     jge    putc1                ;
  79.     inc    word ptr [bx+10]        ;
  80.     mov    bx, [bx+10]            ;
  81.     mov    [bx-1], al            ;
  82.     jmp    short putc2            ;
  83. putc1:                        ;
  84.     call    crcputc                ;
  85. putc2:                        ;
  86.     endm                    ;
  87.                         ;
  88. DGROUP    group    _DATA,_BSS            ;
  89. EGROUP    group    _EXTRA                ;
  90.                         ;
  91.     name    lzsub                ;
  92. _TEXT    segment    byte public 'CODE'        ;
  93.     assume    cs:_TEXT,ds:DGROUP,es:EGROUP,ss:DGROUP
  94. _TEXT    ends                    ;
  95.                         ;
  96. _DATA    segment word public 'DATA'        ;
  97. mark    db    'o'                ;
  98. _DATA    ends                    ;
  99.                         ;
  100. _BSS    segment word public 'BSS'        ;
  101. _BSS    ends                    ;
  102.                         ;
  103. _EXTRA    segment word public            ;
  104. _EXTRA    ends                    ;
  105.                         ;
  106. _TEXT    segment                    ;
  107.                         ;
  108. extrn    DGROUP@        :word            ;
  109. extrn    _outfile    :word            ;
  110. extrn    _infname    :word            ;
  111. extrn    _outfname    :word            ;
  112. extrn    _codesize    :word            ;
  113. extrn    _crc        :word            ;
  114. extrn    _copying    :byte            ;
  115. extrn    _crcflg        :byte            ;
  116. extrn    _tstflg        :byte            ;
  117. extrn    _error        :near            ;
  118. extrn    _ftell        :near            ;
  119. extrn    _fseek        :near            ;
  120.                         ;
  121. N        equ    4096            ; âoâbâtâ@é╠æσé½é│
  122. F        equ    60            ; Éµô╟é▌âoâbâtâ@é╠æσé½é│
  123. THRESHOLD    equ    2            ;
  124. NIL        equ    N            ; û╪é╠ûûÆ[
  125. ROOTMK        equ    -1            ;
  126. F_OLD        equ    18            ; éké`éÆéâùpé╠ɵô╟é▌
  127.                         ;   âoâbâtâ@é╠æσé½é│
  128.     public    _text_buf, _match_position, _match_length
  129.     public    _rson, _lson, _dad, _root, _buf2, _buf3
  130.     public    len                ;
  131.     public    crctbl                ;
  132.     public    extra                ;
  133.                         ;
  134. _BSS            segment            ;
  135. crctbl            dw    100h dup (?)    ;
  136. extra            dw    1 dup (?)    ;
  137. _match_position        dw    1 dup (?)    ;
  138. _match_length        dw    1 dup (?)    ;
  139. len            dw    1 dup (?)    ;
  140. _buf2            db    4096 dup (?)    ;
  141. _buf3            db    4096 dup (?)    ;
  142. _rson            dw    (N + 1) dup (?)    ;
  143. _lson            dw    (N + 1) dup (?)    ;
  144. _dad            dw    (N + 1) dup (?)    ;
  145. _root            dw    (N + 1) dup (?)    ;
  146. _text_buf        db    (N + F - 1) dup (?)
  147. _BSS            ends            ;
  148.                         ;
  149. ;-----------------------------------------------;
  150. ;    û╪ì\æóé╠Åëè·ë╗                ;
  151. ;-----------------------------------------------;
  152. public    _InitTree                ;
  153. _InitTree    proc    near            ;
  154.     push    di                ;
  155.     mov    bx, 1000h            ;
  156.     mov    ah, 48h                ; get memory
  157.     int    21h                ;
  158.     jNC $_1
  159.         xor    ax, ax            ;
  160.         push    ax            ;
  161.         mov    ax, 15            ; MEMOVRERR
  162.         push    ax            ;
  163.         call    _error            ;
  164. $_1:
  165.     mov    DGROUP:extra, ax        ;
  166.     cld                    ;
  167.     mov    es, ax                ;
  168.     mov    ax, NIL * 2            ;
  169.     mov    cx, 8000h            ;
  170.     mov    di, 0                ;
  171.     rep    stosw                ;
  172.     mov    bx, ds                ;
  173.     mov    es, bx                ;
  174.     mov    cx, N                ;
  175.     mov    di, offset DGROUP:_dad        ;
  176.     rep    stosw                ;
  177.     pop    di                ;
  178.     ret                    ;
  179. _InitTree    endp                ;
  180.                         ;
  181. ;-----------------------------------------------;
  182. ;    û╪ì\æóé╔É▀é≡Æ╟ë┴            ;
  183. ;-----------------------------------------------;
  184. public    _InsertNode                ;
  185. _InsertNode    proc    near            ;
  186.     push    si                ;
  187.     push    di                ;
  188.     mov    es, DGROUP:extra        ;
  189.     mov    bx, di                ; di = r
  190.     shl    bx, 1                ;
  191.         add    di, offset DGROUP:_text_buf    ;
  192.                         ;
  193.     mov    ax, [di]            ;
  194.     xor    ah, [di + 2]            ;
  195.     shl    ax, 1                ; si = p
  196.     mov    si, ax                ;
  197.                         ;
  198.     mov    ax, NIL * 2            ;
  199.     mov    DGROUP:_rson[bx], ax        ;
  200.     mov    DGROUP:_lson[bx], ax        ;
  201.                         ;
  202.     cmp    word ptr EGROUP:[si], ax    ; NIL * 2
  203.     jne    in10                ;
  204.         mov    EGROUP:[si], bx        ;
  205.         mov    DGROUP:_dad[bx], ROOTMK    ;
  206.         mov    DGROUP:_root[bx], si    ;
  207.         jmp    in9            ;
  208. in10:                        ;
  209.         mov    bp, EGROUP:[si]        ;
  210.     mov    cx, ds                ;
  211.     mov    es, cx                ;
  212.     cld                    ;
  213.     inc    di                ;
  214.     mov    dx, di                ;
  215.     ;$_while TRUE                ;
  216. in11:                        ;
  217.         mov    di, dx            ;
  218.         mov    si, bp            ;
  219.         shr    si, 1            ;
  220.         add    si, offset DGROUP:_text_buf + 1
  221.         mov    cx, F-1            ;
  222.         repe    cmpsb            ;
  223.         mov    si, bp            ;
  224.         je    in7            ;
  225. in0:                        ;
  226.         ja    in2            ;
  227.             mov    bp, DGROUP:_rson[si]
  228.             cmp    bp, ax        ; NIL * 2
  229.             jne    in11        ;
  230.                 mov    DGROUP:_rson[si], bx
  231.                 mov    DGROUP:_dad[bx], si
  232.                 jmp    in9    ;
  233. in2:                        ;
  234.             mov    bp, DGROUP:_lson[si]
  235.             cmp    bp, ax        ; NIL * 2
  236.             jne    in11        ;
  237.                 mov    DGROUP:_lson[si], bx
  238.                 mov    DGROUP:_dad[bx], si
  239.                 jmp    in9    ;
  240.     ;$_enddo                ;
  241. in7:                        ;
  242.     mov    di, DGROUP:_lson[si]        ;
  243.     mov    DGROUP:_dad[di], bx        ;
  244.     mov    DGROUP:_lson[bx], di        ;
  245.     mov    di, DGROUP:_rson[si]        ;
  246.     mov    DGROUP:_dad[di], bx        ;
  247.     mov    DGROUP:_rson[bx], di        ;
  248.     mov    di, DGROUP:_dad[si]        ;
  249.     mov    DGROUP:_dad[bx], di        ;
  250.                         ;
  251.     mov    word ptr DGROUP:_dad[si], ax    ; NIL * 2
  252.     or di, di
  253.     jNS $_2
  254.                         ; ROOTMK
  255.         mov    es, DGROUP:extra    ;
  256.         mov    di, DGROUP:_root[si]    ;
  257.         mov    DGROUP:_root[bx], di    ;
  258.         mov    EGROUP:[di], bx        ;
  259.         jmp    short in9        ;
  260. $_2:
  261.     cmp DGROUP:_rson[di], si
  262.     jNE $_3
  263.         mov    DGROUP:_rson[di], bx    ;
  264.     jmp short $_4
  265. $_3:
  266.         mov    DGROUP:_lson[di], bx    ;
  267. $_4:
  268.                         ;
  269. in9:                        ;
  270.     pop    di                ;
  271.     pop    si                ;
  272.     ret                    ;
  273. _InsertNode    endp                ;
  274.                         ;
  275. ;-----------------------------------------------;
  276. ;    û╪ì\æóé╔É▀é≡Æ╟ë┴é╡üAì┼éα        ;
  277. ;    êΩÆvé╡é╜Åεò±é≡ò╘é╖üB            ;
  278. ;-----------------------------------------------;
  279. public    _MatchInsertNode            ;
  280. _MatchInsertNode    proc    near        ;
  281.     push    si                ;
  282.     push    di                ;
  283.     mov    es, DGROUP:extra        ;
  284.     mov    bx, di                ; di = r
  285.     shl    bx, 1                ;
  286.         add    di, offset DGROUP:_text_buf    ;
  287.     mov    ax, [di]            ;
  288.     xor    ah, [di + 2]            ;
  289.     shl    ax, 1                ; si = p
  290.     mov    si, ax                ;
  291.                         ;
  292.     mov    ax, NIL * 2            ;
  293.     mov    DGROUP:_rson[bx], ax        ;
  294.     mov    DGROUP:_lson[bx], ax        ;
  295.                         ;
  296.     mov    al, F - 1            ;
  297.     cmp    word ptr EGROUP:[si], NIL * 2    ;
  298.     jne    min10                ;
  299.         mov    EGROUP:[si], bx        ;
  300.         mov    DGROUP:_dad[bx], ROOTMK    ;
  301.         mov    DGROUP:_root[bx], si    ;
  302.         jmp    min9            ;
  303. min10:                        ;
  304.         mov    bp, EGROUP:[si]        ;
  305.     mov    cx, ds                ;
  306.     mov    es, cx                ;
  307.     cld                    ;
  308.     inc    di                ;
  309.     mov    dx, di                ;
  310.     ;$_while TRUE                ;
  311. min11:                        ;
  312.         mov    di, dx            ;
  313.         mov    si, bp            ;
  314.         shr    si, 1            ;
  315.         add    si, offset DGROUP:_text_buf + 1
  316.         mov    cx, F - 1        ;
  317.         repe    cmpsb            ;
  318.         lahf                ;
  319.         je    min7            ;
  320.         cmp    cx, F - THRESHOLD - 1    ;
  321.         jge    min0            ;
  322.         cmp    cl, al            ;
  323.         jg    min0            ;
  324.         je    min5            ;
  325.             mov    al, cl        ;
  326.             sub    di, si        ;
  327.             and    di, N - 1    ;
  328.             mov    DGROUP:_match_position, di
  329.             jmp    min0        ;
  330. min5:                        ;
  331.             sub    di, si        ;
  332.             and    di, N - 1    ;
  333.             cmp    di, DGROUP:_match_position
  334.             jge    min6        ;
  335.                 mov    DGROUP:_match_position, di
  336. min6:                        ;
  337.                         ;
  338. min0:                        ;
  339.         mov    si, bp            ;
  340.         sahf                ;
  341.         ja    min2            ;
  342.             mov    bp, DGROUP:_rson[si]
  343.             cmp    bp, NIL * 2    ;
  344.             jne    min11        ;
  345.                 mov    DGROUP:_rson[si], bx
  346.                 mov    DGROUP:_dad[bx], si
  347.                 jmp    min9    ;
  348. min2:                        ;
  349.             mov    bp, DGROUP:_lson[si]
  350.             cmp    bp, NIL * 2    ;
  351.             jne    min11        ;
  352.                 mov    DGROUP:_lson[si], bx
  353.                 mov    DGROUP:_dad[bx], si
  354.                 jmp    min9    ;
  355.     ;$_enddo                ;
  356. min7:                        ;
  357.     mov    al, -1                ;
  358.     sub    di, si                ;
  359.     and    di, N - 1            ;
  360.     mov    DGROUP:_match_position, di    ;
  361.                         ;
  362.     mov    si, bp                ;
  363.     mov    di, DGROUP:_lson[si]        ;
  364.     mov    DGROUP:_dad[di], bx        ;
  365.     mov    DGROUP:_lson[bx], di        ;
  366.     mov    di, DGROUP:_rson[si]        ;
  367.     mov    DGROUP:_dad[di], bx        ;
  368.     mov    DGROUP:_rson[bx], di        ;
  369.     mov    di, DGROUP:_dad[si]        ;
  370.     mov    DGROUP:_dad[bx], di        ;
  371.                         ;
  372.     mov    word ptr DGROUP:_dad[si], NIL * 2
  373.     or di, di
  374.     jNS $_5
  375.         mov    es, DGROUP:extra    ;
  376.         mov    di, DGROUP:_root[si]    ;
  377.         mov    DGROUP:_root[bx], di    ;
  378.         mov    EGROUP:[di], bx        ;
  379.         jmp    short min9        ;
  380. $_5:
  381.     cmp DGROUP:_rson[di], si
  382.     jNE $_6
  383.         mov    DGROUP:_rson[di], bx    ;
  384.     jmp short $_7
  385. $_6:
  386.         mov    DGROUP:_lson[di], bx    ;
  387. $_7:
  388.                         ;
  389. min9:                        ;
  390.     dec    word ptr DGROUP:_match_position    ;
  391.     cbw                    ;
  392.     neg    ax                ;
  393.     add    ax, F - 1            ;
  394.     mov    DGROUP:_match_length, ax    ;
  395.     pop    di                ;
  396.     pop    si                ;
  397.     ret                    ;
  398. _MatchInsertNode    endp            ;
  399.                         ;
  400. ;-----------------------------------------------;
  401. ;    û╪ì\æóé⌐éτÉ▀é≡ìφÅ£            ;
  402. ;-----------------------------------------------;
  403. public    _DeleteNode                ;
  404. _DeleteNode    proc    near            ;
  405.     push    si                ;
  406.     push    di                ;
  407.     mov    es, DGROUP:extra        ;
  408.                         ;
  409.     mov    dx, NIL * 2            ;
  410.     shl    si, 1                ;
  411.     cmp word ptr DGROUP:_dad[si], dx
  412.     jNE $_8
  413.         jmp    dn9            ;
  414. $_8:
  415.     cmp word ptr DGROUP:_rson[si], dx
  416.     jNE $_10
  417.         mov    di, DGROUP:_lson[si]    ;
  418.         jmp short $_9
  419. $_10:
  420.     cmp word ptr DGROUP:_lson[si], dx
  421.     jNE $_11
  422.         mov    di, DGROUP:_rson[si]    ;
  423.         jmp short $_9
  424. $_11:
  425.         mov    di, DGROUP:_lson[si]    ;
  426.         mov    ax, DGROUP:_rson[di]    ;
  427.         cmp ax, dx
  428.         jE $_13
  429. $_14:
  430.                 mov    di, ax    ;
  431.                 mov    ax, DGROUP:_rson[di]
  432.             cmp ax, dx
  433.             jNE $_14
  434. $_15:
  435.             mov    ax, DGROUP:_lson[di]
  436.             mov    bx, DGROUP:_dad[di]
  437.             mov    cx, bx        ;
  438.             mov    DGROUP:_rson[bx], ax
  439.             mov    bx, DGROUP:_lson[di]
  440.             mov    DGROUP:_dad[bx], cx
  441.             mov    ax, DGROUP:_lson[si]
  442.             mov    DGROUP:_lson[di], ax
  443.             mov    bx, DGROUP:_lson[si]
  444.             mov    DGROUP:_dad[bx], di
  445. $_13:
  446.         mov    ax, DGROUP:_rson[si]    ;
  447.         mov    DGROUP:_rson[di], ax    ;
  448.         mov    bx, DGROUP:_rson[si]    ;
  449.         mov    DGROUP:_dad[bx], di    ;
  450. $_12:
  451. $_9:
  452.     mov    bx, DGROUP:_dad[si]        ;
  453.     mov    DGROUP:_dad[di], bx        ;
  454.     or bx, bx
  455.     jNS $_16
  456.         mov    bx, DGROUP:_root[si]    ;
  457.         mov    DGROUP:_root[di], bx    ;
  458.         mov    EGROUP:[bx], di        ;
  459.     jmp short $_17
  460. $_16:
  461.         cmp DGROUP:_rson[bx], si
  462.         jNE $_18
  463.             mov    DGROUP:_rson[bx], di
  464.         jmp short $_19
  465. $_18:
  466.             mov    DGROUP:_lson[bx], di
  467. $_19:
  468. $_17:
  469.     mov    DGROUP:_dad[si], dx        ;
  470. dn9:                        ;
  471.     pop    di                ;
  472.     pop    si                ;
  473.     ret                    ;
  474. _DeleteNode    endp                ;
  475.                         ;
  476. extrn    _textsize    :word            ;
  477.                         ;
  478. extrn    _infile        :word            ;
  479. extrn    _StartModel    :near            ;
  480. extrn    _EncodeChar    :near            ;
  481. extrn    _EncodePosition    :near            ;
  482. extrn    _EncodeEnd    :near            ;
  483.                         ;
  484. extrn    _outfile    :word            ;
  485. extrn    _DecodeChar    :near            ;
  486. extrn    _DecodePosition    :near            ;
  487.                         ;
  488. extrn    _blkcnt        :word            ;
  489. extrn    _curcnt        :word            ;
  490. extrn    _nxtcnt        :word            ;
  491.                         ;
  492. ;-----------------------------------------------;
  493. ;    LArc type 5 é╠ buffer Åëè·ë╗        ;
  494. ;-----------------------------------------------;
  495. public    InitBuf                    ;
  496. InitBuf    proc    near                ;
  497.     cld                    ;
  498.     mov    di, ds                ;
  499.     mov    es, di                ;
  500.     mov    di, offset DGROUP:_text_buf    ;
  501.     mov    al, 0                ;
  502.     mov    bx, 13                ;
  503. $_20:
  504.         mov    cx, bx            ;
  505.         rep    stosb            ;
  506.         inc    al            ;
  507.     jNZ $_20
  508. $_21:
  509. $_22:
  510.         stosb                ;
  511.         inc    al            ;
  512.     jNZ $_22
  513. $_23:
  514. $_24:
  515.         dec    al            ;
  516.         stosb                ;
  517.     jNZ $_24
  518. $_25:
  519.     mov    cx, 128                ;
  520.     rep    stosb                ;
  521.     mov    cx, 128                ;
  522.     mov    al, 20h                ;
  523.     rep    stosb                ;
  524.     ret                    ;
  525. InitBuf    endp                    ;
  526.                         ;
  527. ;-----------------------------------------------;
  528. ;    LZHUF é╠ encode                ;
  529. ;-----------------------------------------------;
  530. public    _Encode                    ;
  531. _Encode    proc    near                ;
  532.     push    si                ;
  533.     push    di                ;
  534.     push    bp                ;
  535.     mov    ax,word ptr DGROUP:_textsize    ;
  536.     or    ax,word ptr DGROUP:_textsize + 2;
  537.     jNZ $_26
  538.         jmp    en05            ;
  539. $_26:
  540.     call    near ptr _StartModel        ;
  541.     call    near ptr _InitTree        ;
  542.     call    near ptr InitBuf        ;
  543.     mov    cx, F                ;
  544.     sub    di, cx                ;
  545. en01:                        ;
  546.     mov    bx, DGROUP:_infile        ;
  547.     getc_crc@                ;
  548.     or    ax, ax                ;
  549.     js    en02                ;
  550.     stosb                    ;
  551.     loop    en01                ;
  552. en02:                        ;
  553.     mov    ax, F                ;
  554.     sub    ax, cx                ;
  555.     mov    word ptr len, ax        ;
  556.     xor    ax, ax                ;
  557.     mov    word ptr DGROUP:_textsize, ax    ;
  558.     mov    word ptr DGROUP:_textsize + 2, ax
  559.     mov    di, N - F            ;
  560.     mov    si, di                ;
  561.     mov    cx, F                ;
  562. $_27:
  563.         dec    di            ;
  564.         push    cx            ;
  565.         call    _InsertNode        ;
  566.         pop    cx            ;
  567.     LOOP $_27
  568. $_28:
  569.     mov    di, si                ;
  570.     call    near ptr _MatchInsertNode    ;
  571.     xor    si, si                ;
  572. $_29:
  573.         mov    bx, word ptr DGROUP:_match_length
  574.         cmp bx, word ptr len
  575.         jLE $_31
  576.             mov    bx, word ptr len;
  577.             mov    word ptr DGROUP:_match_length, bx
  578. $_31:
  579.         push    si            ;
  580.         push    di            ;
  581.         cmp bx, THRESHOLD
  582.         jG $_32
  583.             mov    word ptr DGROUP:_match_length, 1
  584.             mov    bl, byte ptr DGROUP:_text_buf[di]
  585.             mov    bh, 0        ;
  586.             call    near ptr _EncodeChar
  587.         jmp short $_33
  588. $_32:
  589.             add    bx, 255 - THRESHOLD
  590.             call    near ptr _EncodeChar
  591.             mov    bx, DGROUP:_match_position
  592.             call    near ptr _EncodePosition
  593. $_33:
  594.         pop    di            ;
  595.         pop    si            ;
  596.         mov    ax, word ptr DGROUP:_match_length
  597.         add    word ptr DGROUP:_textsize, ax
  598.         adc    word ptr DGROUP:_textsize + 2, 0
  599.         jmp    short en03        ;
  600. $_34:
  601.             call    near ptr _InsertNode
  602. en03:                        ;
  603.             call    near ptr _DeleteNode
  604.             mov    bx, DGROUP:_infile
  605.             getc_crc@        ;
  606.             or ax, ax
  607.             jS $_36
  608.                 mov    byte ptr DGROUP:_text_buf[si], al
  609.                 cmp si, F - 1
  610.                 jAE $_37
  611.                     mov    DGROUP:_text_buf[si + N], al
  612. $_37:
  613.             jmp short $_38
  614. $_36:
  615.                 dec    word ptr len
  616. $_38:
  617.             inc    si        ;
  618.             inc    di        ;
  619.             and    si, N - 1    ;
  620.             and    di, N - 1    ;
  621.         dec _match_length
  622.         jNZ $_34
  623. $_35:
  624.         call    near ptr _MatchInsertNode
  625.     cmp len, 0
  626.     jLE $_39
  627.     jmp $_29
  628. $_30:
  629. $_39:
  630.     call    near ptr _EncodeEnd        ;
  631.                         ;
  632.     mov    es, DGROUP:extra        ;
  633.     mov    ah, 49h                ; release memory
  634.     int    21h                ;
  635. en05:                        ;
  636.     pop    bp                ;
  637.     pop    di                ;
  638.     pop    si                ;
  639.     ret                    ;
  640. _Encode    endp                    ;
  641.                         ;
  642. ;-----------------------------------------------;
  643. ;    LZHUF é╠ decode                ;
  644. ;-----------------------------------------------;
  645.     public    _Decode                ;
  646. _Decode    proc    near                ;
  647.     push    si                ;
  648.     push    di                ;
  649.     push    bp                ;
  650.     mov    ax, word ptr DGROUP:_textsize    ;
  651.     or    ax, word ptr DGROUP:_textsize+2    ;
  652.     jNZ $_40
  653.         jmp    de9            ;
  654. $_40:
  655.     call    near ptr _StartModel        ;
  656.     call    near ptr InitBuf        ;
  657.     mov    di, N - F            ;
  658. $_41:
  659.         push    di            ;
  660.         call    near ptr _DecodeChar    ;
  661.         mov    di, ax            ;
  662.         cmp ax, 256
  663.         jGE $_43
  664.             pop    di        ;
  665.             mov    bx, word ptr DGROUP:_outfile
  666.             putc_crc@        ;
  667.             mov    byte ptr DGROUP:_text_buf[di], al
  668.             inc    di        ;
  669.             and    di, N - 1    ;
  670.             sub    DGROUP:_textsize, 1
  671.             sbb    DGROUP:_textsize + 2, 0
  672.         jmp short $_44
  673. $_43:
  674.             call    near ptr _DecodePosition
  675.             mov    cx, di        ;
  676.             pop    di        ;
  677.             mov    si, di        ;
  678.             sub    si, ax        ;
  679.             dec    si        ;
  680.             and    si, N - 1    ;
  681.             sub    cx, 255 - THRESHOLD
  682.             sub    DGROUP:_textsize, cx
  683.             sbb    DGROUP:_textsize + 2, 0
  684.             mov    dx, DGROUP:_outfile
  685. $_45:
  686.                 mov    al, DGROUP:_text_buf[si]
  687.                 mov    DGROUP:_text_buf[di], al
  688.                 inc    si    ;
  689.                 inc    di    ;
  690.                 and    si, N - 1
  691.                 and    di, N - 1
  692.                 mov    bx, dx    ;
  693.                 putc_crc@    ;
  694.             LOOP $_45
  695. $_46:
  696. $_44:
  697.         mov    ax, word ptr DGROUP:_textsize+2
  698.     or ax, ax
  699.     jS $_47
  700.     or ax, word ptr DGROUP:_textsize
  701.     jZ $_47
  702.     jmp $_41
  703. $_42:
  704. $_47:
  705. de9:                        ;
  706.     call    crcend                ;
  707.     pop    bp                ;
  708.     pop    di                ;
  709.     pop    si                ;
  710.     ret                    ;
  711. _Decode    endp                    ;
  712.                         ;
  713. ;-----------------------------------------------;
  714. ;    LArc type 5 é╠ decode            ;
  715. ;-----------------------------------------------;
  716.         public    _DecodeOld        ;
  717. _DecodeOld    proc    near            ;
  718.     push    si                ;
  719.     push    di                ;
  720.     push    bp                ;
  721.     push    ds                ;
  722.     pop    es                ;
  723.     mov    ax, word ptr DGROUP:_textsize    ;
  724.     or    ax, word ptr DGROUP:_textsize+2    ;
  725.     jNZ $_48
  726.         jmp    do9            ;
  727. $_48:
  728.     call    near ptr InitBuf        ;
  729.     mov    di, N - F_OLD            ;
  730.     mov    dl, 80h                ;
  731. $_49:
  732.         rol dl, 1
  733.         jNC $_51
  734.             mov    bx, word ptr DGROUP:_infile
  735.             getc@            ;
  736.             mov    dh, al        ;
  737. $_51:
  738.         mov    bx, word ptr DGROUP:_infile
  739.         getc@                ;
  740.         test dh, dl
  741.         jZ $_52
  742.             mov    bx, word ptr DGROUP:_outfile
  743.             putc_crc@        ;
  744.             mov    byte ptr DGROUP:_text_buf[di], al
  745.             inc    di        ;
  746.             and    di, N - 1    ;
  747.             sub    DGROUP:_textsize, 1
  748.             sbb    DGROUP:_textsize + 2, 0
  749.         jmp short $_53
  750. $_52:
  751.             mov    cl, al        ;
  752.             mov    bx, word ptr DGROUP:_infile
  753.             getc@            ;
  754.             mov    ch, al        ;
  755.             shr    ch, 1        ;
  756.             shr    ch, 1        ;
  757.             shr    ch, 1        ;
  758.             shr    ch, 1        ;
  759.             mov    si, cx        ;
  760.             and    ax, 000fh    ;
  761.             add    ax, 3        ;
  762.             mov    cx, ax        ;
  763.             sub    DGROUP:_textsize, cx
  764.             sbb    DGROUP:_textsize + 2, 0
  765. $_54:
  766.                 mov    al, DGROUP:_text_buf[si]
  767.                 mov    DGROUP:_text_buf[di], al
  768.                 mov    bx, DGROUP:_outfile
  769.                 putc_crc@    ;
  770.                 inc    si    ;
  771.                 inc    di    ;
  772.                 and    si, N - 1
  773.                 and    di, N - 1
  774.             LOOP $_54
  775. $_55:
  776. $_53:
  777.         mov    ax, word ptr DGROUP:_textsize+2
  778.     or ax, ax
  779.     jS $_56
  780.     or ax, word ptr DGROUP:_textsize
  781.     jZ $_56
  782.     jmp $_49
  783. $_50:
  784. $_56:
  785. do9:                        ;
  786.     call    crcend                ;
  787.     pop    bp                ;
  788.     pop    di                ;
  789.     pop    si                ;
  790.     ret                    ;
  791. _DecodeOld    endp                ;
  792.                         ;
  793. ;-----------------------------------------------;
  794. ;    sub-module for                 ;
  795. ;      calculate CRC in buffer        ;
  796. ;-----------------------------------------------;
  797. ;    ax = _crc                ;
  798. ;    cx = length                ;
  799. ;    si = buffer                ;
  800. ;-----------------------------------------------;
  801. MAXBLK    equ    64                ;
  802.                         ;
  803.     public    crcsub                ;
  804. crcsub    proc    near                ;
  805.     jcxz    crcsub9                ;
  806.     mov    ax, DGROUP:_curcnt        ;
  807.     inc    DGROUP:_curcnt            ;
  808.     cmp ax, DGROUP:_nxtcnt
  809.     jB $_57
  810.         push    bx            ;
  811.         push    dx            ;
  812.         push    cx            ;
  813.         push    ax            ;
  814.         mov    ah, 40h            ; output char to stderr
  815.         mov    bx, 2            ;
  816.         mov    cx, 1            ;
  817.         mov    dx, offset DGROUP:mark    ;
  818.         int    21h            ;
  819.         pop    ax            ;
  820.         pop    cx            ;
  821.         cmp DGROUP:_blkcnt, MAXBLK
  822.         jBE $_58
  823.             mov    bx, MAXBLK    ; calculation of next blk
  824.             mul    bx        ;
  825.             mov    bx, DGROUP:_blkcnt
  826.             dec    bx        ;
  827.             add    ax, bx        ;
  828.             adc    dx, 0        ;
  829.             inc    bx        ;
  830.             div    bx        ;
  831.             inc    ax        ;
  832.             mul    bx        ;
  833.             mov    bx, MAXBLK    ;
  834.             div    bx        ;
  835.         jmp short $_59
  836. $_58:
  837.             inc    ax        ;
  838. $_59:
  839.         mov    DGROUP:_nxtcnt, ax    ;
  840.         pop    dx            ;
  841.         pop    bx            ;
  842. $_57:
  843.     mov    ax, DGROUP:_crc            ;
  844.     push    bx                ;
  845. $_60:
  846.         xor    al, [si]        ;
  847.         inc    si            ;
  848.         mov    bl, al            ; crc & 0xff
  849.         xor    bh, bh            ;
  850.         mov    al, ah            ; crc >> 8
  851.         xor    ah, ah            ;
  852.         shl    bx, 1            ;
  853.         xor    ax, crctbl[bx]        ;
  854.     LOOP $_60
  855. $_61:
  856.     pop    bx                ;
  857.     mov    DGROUP:_crc, ax            ;
  858. crcsub9:                    ;
  859.     ret                    ;
  860. crcsub    endp                    ;
  861.                         ;
  862. ;-----------------------------------------------;
  863. ;    get CRC for putc in buffer        ;
  864. ;-----------------------------------------------;
  865.     public    crcbuf                ;
  866. crcbuf    proc    near                ;
  867.     push    cx                ;
  868.     push    si                ;
  869.     mov    cx, 10[bx]            ;
  870.     mov    si, 8[bx]            ;
  871.     sub    cx, si                ;
  872.     mov    bl, 4[bx]            ;
  873.     call    crcsub                ;
  874.     pop    si                ;
  875.     pop    cx                ;
  876.     ret                    ;
  877. crcbuf    endp                    ;
  878.                         ;
  879. ;-----------------------------------------------;
  880. ;    end process of CRC for putc        ;
  881. ;-----------------------------------------------;
  882.     public    crcend                ;
  883. crcend    proc    near                ;
  884.     mov    bx, DGROUP:_outfile        ;
  885.     test word ptr 2[bx], 0200h
  886.     jZ $_62
  887.     cmp  byte ptr 4[bx], 01h
  888.     jE $_63
  889. $_62:
  890.         call    crcbuf            ;
  891. $_63:
  892.     ret                    ;
  893. crcend    endp                    ;
  894.                         ;
  895. ;-----------------------------------------------;
  896. ;    CRC & putc                ;
  897. ;-----------------------------------------------;
  898.     public    crcputc                ;
  899. crcputc    proc    near                ;
  900.     push    bx                ;
  901.     push    ax                ;
  902.     test word ptr 2[bx], 0200h
  903.     jZ $_64
  904.     cmp  byte ptr 4[bx], 01h
  905.     jE $_65
  906. $_64:
  907.         call    crcbuf            ;
  908.     jmp short $_66
  909. $_65:
  910.         xor    al, byte ptr DGROUP:_crc;
  911.         mov    bl, al            ;
  912.         xor    bh, bh            ;
  913.         shl    bx, 1            ;
  914.         mov    ax, crctbl[bx]        ;
  915.         xor    al, byte ptr DGROUP:_crc + 1
  916.         mov    DGROUP:_crc, ax        ;
  917. $_66:
  918.     pop    ax                ;
  919.     pop    bx                ;
  920.     cmp DGROUP:_tstflg, 0
  921.     jE $_67
  922.         push    cx            ;
  923.         push    bx            ;
  924.         mov    cx, 6[bx]        ;
  925.         neg    cx            ;
  926.         mov    [bx], cx        ;
  927.         mov    cx, 8[bx]        ;
  928.         inc    cx            ;
  929.         mov    10[bx], cx        ;
  930.         mov    bx, cx            ;
  931.         mov    [bx - 1], al        ;
  932.         pop    bx            ;
  933.         pop    cx            ;
  934.         ret                ;
  935. $_67:
  936.                         ;
  937.     public    fputc                ;
  938. fputc    proc    near                ;
  939.     push    dx                ;
  940.     push    cx                ;
  941.     push    bx                ;
  942.     push    ax                ;
  943.     call    __fputc                ;
  944.     inc    sp                ;
  945.     inc    sp                ;
  946.     pop    bx                ;
  947.     or ax, ax
  948.     jNS $_68
  949.         push    DGROUP:_outfname    ;
  950.         mov    ax, 14            ; WTERR
  951.         push    ax            ;
  952.         call    near ptr _error        ;
  953. $_68:
  954.     pop    cx                ;
  955.     pop    dx                ;
  956.     ret                    ;
  957. fputc    endp                    ;
  958. crcputc    endp                    ;
  959.                         ;
  960. ;-----------------------------------------------;
  961. ;    CRC & getc                ;
  962. ;-----------------------------------------------;
  963.     public    crcgetc                ;
  964. crcgetc    proc    near                ;
  965.     push    dx                ;
  966.     push    cx                ;
  967.     push    bx                ;
  968.     call    __fgetc                ;
  969.     pop    bx                ;
  970.     or ax, ax
  971.     jS $_69
  972.         push    si            ;
  973.         push    ax            ;
  974.         mov    si, 8[bx]        ;
  975.         mov    cx, [bx]        ;
  976.         inc    cx            ;
  977.         call    crcsub            ;
  978.         pop    ax            ;
  979.         pop    si            ;
  980. $_69:
  981.     pop    cx                ;
  982.     pop    dx                ;
  983.     ret                    ;
  984. crcgetc    endp                    ;
  985.                         ;
  986. ;-----------------------------------------------;
  987. ;    make CRC table                ;
  988. ;-----------------------------------------------;
  989.     public    _mkcrc                ;
  990. _mkcrc    proc    near                ;
  991.     mov    bx, offset DGROUP:crctbl    ;
  992.     xor    dx, dx                ;
  993. $_70:
  994.         mov    ax, dx            ;
  995.         mov    cx, 8            ;
  996. $_72:
  997.             shr ax, 1
  998.             jNC $_74
  999.                 xor    ax, 0a001h
  1000. $_74:
  1001.         LOOP $_72
  1002. $_73:
  1003.         mov    [bx], ax        ;
  1004.         inc    bx            ;
  1005.         inc    bx            ;
  1006.     inc dl
  1007.     jNZ $_70
  1008. $_71:
  1009.     ret                    ;
  1010. _mkcrc    endp                    ;
  1011.                         ;
  1012. ;-----------------------------------------------;
  1013. ;    get CRC for _copyfile            ;
  1014. ;-----------------------------------------------;
  1015.     public    _getcrc                ;
  1016. _getcrc    proc    near                ;
  1017.     push    si                ;
  1018.     push    cx                ;
  1019.     mov    si, offset DGROUP:_buf2        ;
  1020.     call    crcsub                ;
  1021.     pop    cx                ;
  1022.     pop    si                ;
  1023.     ret                    ;
  1024. _getcrc    endp                    ;
  1025.                         ;
  1026. ;-----------------------------------------------;
  1027. ;    ìéæ¼âRâsü[                ;
  1028. ;-----------------------------------------------;
  1029. ; void copyfile(FILE *f0, FILE *f1, long size)    ;
  1030. ;-----------------------------------------------;
  1031.     public    _copyfile            ;
  1032. _copyfile    proc    near            ;
  1033. __f0    =    4                ;
  1034. __f1    =    6                ;
  1035. __size    =    8                ;
  1036.     push    bp                ;
  1037.     mov    bp, sp                ;
  1038.     mov    DGROUP:_crc, 0            ;
  1039.     mov    ax, __size[bp]            ;
  1040.     or    ax, __size + 2[bp]        ;
  1041.     jNZ $_75
  1042.         jmp    cf9            ;
  1043. $_75:
  1044.                         ;
  1045.     push    si                ;
  1046.     push    di                ;
  1047.     mov    si, __f0[bp]            ;
  1048.     mov    di, __f1[bp]            ;
  1049.                         ;
  1050.     push    si                ;
  1051.     call    _ftell                ;
  1052.     pop    cx                ;
  1053.     mov    cx, dx                ;
  1054.     mov    dx, ax                ;
  1055.     mov    bl, 4[si]            ;
  1056.     xor    bh, bh                ;
  1057.     mov    si, bx                ; fd0
  1058.     mov    ax, 4200h            ;
  1059.     int    21h                ; lseek
  1060.                         ;
  1061.     push    di                ;
  1062.     call    _ftell                ;
  1063.     pop    cx                ;
  1064.     mov    cx, dx                ;
  1065.     mov    dx, ax                ;
  1066.     mov    bl, 4[di]            ;
  1067.     xor    bh, bh                ;
  1068.     mov    di, bx                ; fd1
  1069.     mov    ax, 4200h            ;
  1070.     int    21h                ; lseek
  1071.                         ;
  1072.     mov    dx, offset DGROUP:_buf2        ;
  1073. $_76:
  1074.         mov    cx, 0a000h        ;
  1075.         cmp DGROUP:_crcflg, 0
  1076.         jE $_78
  1077.             mov    cx, 01000h    ;
  1078. $_78:
  1079.         cmp word ptr __size + 2[bp], 0
  1080.         jNZ $_79
  1081.         cmp cx, __size[bp]
  1082.         jBE $_79
  1083.             mov    cx, __size[bp]    ;
  1084. $_79:
  1085.         mov    bx, si            ;
  1086.         mov    ah, 3fh            ;
  1087.         int    21h            ;
  1088.         jC $_80
  1089.         cmp ax, cx
  1090.         jE $_81
  1091. $_80:
  1092.             push    DGROUP:_infname    ;
  1093.             mov    ax, 13        ; RDERR
  1094.             push    ax        ;
  1095.             call    _error        ;
  1096. $_81:
  1097.         cmp DGROUP:_tstflg, 0
  1098.         jNE $_82
  1099.             mov    bx, di        ;
  1100.             mov    ah, 40h        ;
  1101.             int    21h        ;
  1102.             jC $_83
  1103.                 dec    bx    ; STDOUT ?
  1104.                 jne    cf1    ;
  1105.                 mov    ax, cx    ;
  1106. cf1:                        ;
  1107.                 inc    bx    ;
  1108.             cmp ax, cx
  1109.             jE $_84
  1110. $_83:
  1111.                 push    DGROUP:_outfname
  1112.                 mov    ax, 14    ; WTERR
  1113.                 push    ax    ;
  1114.                 call    _error    ;
  1115. $_84:
  1116. $_82:
  1117.         sub    __size[bp], ax        ;
  1118.         sbb    word ptr __size + 2[bp], 0
  1119.         cmp DGROUP:_crcflg, 0
  1120.         jE $_85
  1121.             call    _getcrc        ;
  1122. $_85:
  1123.         mov    ax, __size[bp]        ;
  1124.         or    ax, __size + 2[bp]    ;
  1125.     jNZ $_76
  1126. $_77:
  1127.                         ;
  1128.     xor    cx, cx                ;
  1129.     mov    bx, di                ;
  1130.     mov    ah, 40h                ; to abandon rest of old file
  1131.     int    21h                ;
  1132.                         ;
  1133.     push    cx                ;
  1134.     mov    dx, cx                ;
  1135.     mov    bx, si                ;
  1136.     mov    ax, 4201h            ; lseek
  1137.     int    21h                ;
  1138.     push    dx                ;
  1139.     push    ax                ;
  1140.     push    word ptr __f0[bp]        ;
  1141.     call    near ptr _fseek            ;
  1142.     add    sp, 8                ;
  1143.                         ;
  1144.     xor    cx, cx                ;
  1145.     push    cx                ;
  1146.     mov    dx, cx                ;
  1147.     mov    bx, di                ;
  1148.     mov    ax, 4201h            ; lseek
  1149.     int    21h                ;
  1150.     push    dx                ;
  1151.     push    ax                ;
  1152.     push    word ptr __f1[bp]        ;
  1153.     call    near ptr _fseek            ;
  1154.     add    sp, 8                ;
  1155.                         ;
  1156.     pop    di                ;
  1157.     pop    si                ;
  1158. cf9:                        ;
  1159.     pop    bp                ;
  1160.     ret                    ;
  1161. _copyfile    endp                ;
  1162.                         ;
  1163. _TEXT    ends                    ;
  1164.     end                    ;
  1165.